#ifndef WOLF_SPRITE_TEST
#define WOLF_SPRITE_TEST

#include "test.hpp"
#include "sprite.hpp"

namespace wolf
{
    /**
     * @brief Tests if the sprite system is working
     *
     * It creates a sprite using a image_file, and, alters it velocity when press '->' or '<-'.
     **/
    class SpriteTest: public Test
    {
    public:
        class MyEventHandler: public Manager
        {
        public:
            bool onEvent( Engine &engine, SDL_Event &event )
            {
                if( event.type == SDL_KEYDOWN )
                {
                    if( event.key.keysym.sym == SDLK_DOWN )
                    {
                        if( _velocity ) _velocity -= 0.25;
                        _sprite->setVelocity( _velocity );
                    }
                    else if( event.key.keysym.sym == SDLK_UP )
                    {
                        if( _velocity < 2.0 ) _velocity += 0.25;
                        _sprite->setVelocity( _velocity );
                    }
                }
                return true;
            }
            void onDraw( Engine &engine, SDL_Surface *dst )
            {
                _sprite->draw( dst, 15, 15 );
            }
            void onFrame( Engine &engine ) {}
        } myEventHandler;

        SpriteTest(): Test( "Sprite" )
        {
            _velocity = 0;
            _this = this;
        }
        ~SpriteTest() {}

        bool run( void )
        {
            Engine engine( Engine::DEBUG );
            engine.setVideoMode( 640, 480, 0 );
            engine.setFrameRate( 30 );

            engine.addManager( myEventHandler );
            engine.start();

            Sprite sprite( "resource/spritetest.png", 4, 1 ); // Use a sprite on folder resource.
            _sprite = &sprite;

            //
            while( engine.isRunning() )
            {
                engine.doFrame();
            }
            engine.halt();
            return true;
        }

    private:
        static double _velocity;
        static Sprite *_sprite;
        static SpriteTest* _this;
    };

    double SpriteTest::_velocity;
    Sprite *SpriteTest::_sprite;
    SpriteTest* SpriteTest::_this;

}

#endif // WOLF_SPRITE_TEST

